package com.ym.b2b.provider.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.provider.dao.EmBProviderProductDAO;
import com.ym.b2b.provider.sqlbean.EmBProviderProduct;
import com.zc.commons.base.Page;
import com.zc.commons.dao.ZcDao;

@Repository
public class EmBProviderProductDAOImpl<T> extends ZcDao<T> implements EmBProviderProductDAO {

    public Long searchPageEmBProviderProductNum(EmBProviderProduct embproviderproduct) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embproviderproduct);
        return (Long) find("EM_B_PROVIDER_PRODUCT.searchPageEmBProviderProductNum", map);
    }

    public Page searchPageEmBProviderProduct(EmBProviderProduct embproviderproduct, Page<EmBProviderProduct> page)
                                                                                                                  throws DataAccessException {
        page.setTotalRow(searchPageEmBProviderProductNum(embproviderproduct));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embproviderproduct);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_B_PROVIDER_PRODUCT.searchPageEmBProviderProduct", map));
        return page;
    }

    public void insertEmBProviderProduct(EmBProviderProduct record) throws DataAccessException {
        insert("EM_B_PROVIDER_PRODUCT.insertEmBProviderProduct", record);
    }

    public int updateEmBProviderProduct(EmBProviderProduct record) throws DataAccessException {
        int rows = update("EM_B_PROVIDER_PRODUCT.updateEmBProviderProduct", record);
        return rows;
    }

    public EmBProviderProduct searchEmBProviderProduct(Long providerProductId) throws DataAccessException {
        EmBProviderProduct key = new EmBProviderProduct();
        key.setProviderProductId(providerProductId);
        EmBProviderProduct record = (EmBProviderProduct) find("EM_B_PROVIDER_PRODUCT.selectEmBProviderProduct", key);
        return record;
    }

    public void deleteEmBProviderProduct(EmBProviderProduct record) throws DataAccessException {
        delete("EM_B_PROVIDER_PRODUCT.deleteEmBProviderProduct", record);
    }

    @Override
    public void deleteMultipleEmBProviderProducts(String providerProductIdList) {
        delete("EM_B_PROVIDER_PRODUCT.deleteMultipleEmBProviderProducts", providerProductIdList);
    }

    /**
     * 根据providerCode查询所属产品list
     * <p>Title: getProviderProductList</p>
     */
	@Override
	public List<EmBProviderProduct> getProviderProductList(String providerCode) throws DataAccessException {
		return list("EM_B_PROVIDER_PRODUCT.getProviderProductList", providerCode);
	}
}
